$(document).ready(function(){
	if ($(".child-container").length){
		$(".child-container").msDropDown();
		
		$(".child-container").change(function(){
			if ($(this).val() != ''){
				$(this).parent().parent().next().html('<img src="' + settings.base_url + 'application/assets/images/ajax_loader.gif" style="width:36px;height:36px;" />');
				var id = $(this).val();
				var el = $(this);
				$.ajax({
					 url: settings.base_url + lang.lang_key + '/compare/get_prod_details/' + id,
				     dataType: 'json',
				     type: 'POST',
				     success: function(data){
				    	 if (data.status){
				    		 $(el).parent().parent().next().html(data.html);
				          }
				    	 
				    	 $("#ring_size_" + data.id).msDropDown();
				     },
				})
			} else {
				$(this).parent().parent().next().html('');
			}
		});
	}
	
	$("#send").click(function(){
		if ($("#email").val() == '' || $("#name").val() == ''){
			var msg = '[compare_page_no_dates]';
			if (lang.compare_page_no_dates != 'undefined'){
				msg = lang.compare_page_no_dates;
			}

			alert(msg);
			return false;
		}
		var html = $("#compare-content").html();
		
		$("#compare-content select option:selected").each(function(){
			var selected_text = $(this).text();
			var search_text = $(this).parent().parent().parent().html();

			html = html.replace(search_text,selected_text);
					
		});
	
		$.ajax({
			 url: settings.base_url + lang.lang_key + '/compare/send_page/',
		     dataType: 'json',
		     type: 'POST',
		     data:{
		    	html: html ,
		    	name: $("#name").val(),
		    	email: $("#email").val()
		     },
		     success: function(data){
		    	 if (data.status){
		    		var msg = '[compare_page_sent]';
	    			if (lang.compare_page_sent != 'undefined'){
	    				msg = lang.compare_page_sent;
	    			}
		          } else {
					var msg = '[compare_page_not_sent]';
					if (lang.compare_page_not_sent != 'undefined'){
						msg = lang.compare_page_not_sent;
					} 
		          }
		    	 
		    	 alert(msg);
		     },
		})
	});
	
	for (var i=1;i<=$("#number_of_items").val();i++){
		$.fn.raty.defaults.path = settings.base_url + 'application/assets/js/jqueryPlugins/Rating';
		$('#star_' + i).raty({
			half  : true,
			score : $("#rating_"+i).val(),
			readOnly: true,
			hintList:  ['', '', '', '', ''],
			starHalf   : 'img/star-half-big.png',
			starOff    : 'img/star-off-big.png',
			starOn     : 'img/star-on-big.png',
			click : function(score, evt) {
				return false;
			  }
		});
	}
	
	$(".compare-star").hover(function(){return false;});
	
	var email_contact = '[email_contact]';
	if (lang.email_contact != 'undefined'){
		email_contact = lang.email_contact;
	}
	
	$("#email").focus(function(){
		if ($(this).val() == email_contact){
			$(this).val('');
		}
	});
	$("#email").blur(function(){
		if ($(this).val() == ''){
			$(this).val(email_contact);
		}
	});
		
	var your_name = '[your_name]';
	if (lang.your_name != 'undefined'){
		your_name = lang.your_name;
	}
	
	$("#name").focus(function(){
		if ($(this).val() == your_name){
			$(this).val('');
		}
	});
	$("#name").blur(function(){
		if ($(this).val() == ''){
			$(this).val(your_name);
		}
	});
	
});

function removeCol(id){
	$("#" + id).remove();
}

function addToBasket(id){
	if ($("#ring_size_" + id).val() == ''){
		var msg = '[no_size_error]';
		if (lang.no_size_error != 'undefined'){
			msg = lang.no_size_error;
		}
		
		alert(msg);
		return false;
	}
	$("#add-to-cart-size").val($("#ring_size_" + id).val());
	$("#add-to-cart-form").attr('action',settings.base_url + lang.lang_key + "/cart/addToCart/" + id);

	$("#add-to-cart-form").submit();
}